package com.foreknow.elm.controller;

import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UserController {
    private UserService service = new UserServiceImpl();

    /**
     * 根据用户编号与密码查询用户信息
     * @param request
     * @return
     * @throws Exception
     */
    public Object getUserByIdByPass(HttpServletRequest request)throws Exception{
        //获取请求参数 BusinessController/listBusinessByOrderTypeId?orderTypeId=1
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        //调用service的方法
        User user = service.getUserByIdByPass(userId,password);
        return user;
    }

    /**
     * 根据用户编号查询用户表返回的行数
     * @param request
     * @return
     * @throws Exception
     */
    public Object getUserById(HttpServletRequest request)throws Exception{
        String userId = request.getParameter("userId");
        Integer result = service.getUserById(userId);
        return result;
    }

    /**
     * 向用户表中添加一条记录
     * @param request
     * @return
     * @throws Exception
     */
    public Object saveUser(HttpServletRequest request)throws Exception{
        User user = new User();
        user.setUserId(request.getParameter("userId"));
        user.setPassword(request.getParameter("password"));
        user.setUserName(request.getParameter("userName"));
        user.setUserSex( Integer.valueOf(request.getParameter("userSex")));
        Integer result = service.saveUser(user);
        return result;
    }
}
